﻿using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.MODEL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace KPIS.GERP.GFMS.SERVICE
{
    /// <summary>
    /// Summary description for FIM_MoneyRequestTravelers
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class FIM_MoneyRequestTravelers : System.Web.Services.WebService
    {
        IBLL_FIM_MoneyRequestTravelers bll = new B_FIM_MoneyRequestTravelers();

        public Nullable<int> ConvertNullInt(Object o)
        {
            Nullable<int> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<int>)Convert.ToInt32(o)));
            return result;
        }

        public Nullable<double> ConvertNullDouble(Object o)
        {
            Nullable<double> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<double>)Convert.ToDouble(o)));
            return result;
        }

        public Nullable<DateTime> ConvertNullDateTime(Object o)
        {
            Nullable<DateTime> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<DateTime>)Convert.ToDateTime(o)));
            return result;
        }

        public Nullable<TimeSpan> ConvertNullTimeSpan(Object o)
        {
            Nullable<TimeSpan> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<TimeSpan>)Convert.ToDateTime(o).TimeOfDay));
            return result;
        }

        public Nullable<decimal> ConvertNullDecimal(Object o)
        {
            Nullable<decimal> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<decimal>)Convert.ToDecimal(o)));
            return result;
        }

        [WebMethod]
        public List<M_FIM_MoneyRequestTravelers> GetFull(string money_req_seq)
        {
            DataTable dtb = bll.GetFull(money_req_seq);
            var models = new List<M_FIM_MoneyRequestTravelers>();

            foreach (DataRow dr in dtb.Rows)
            {
                var model = new M_FIM_MoneyRequestTravelers();
                model.traveler_seq = Convert.ToInt32(dr["traveler_seq"]);
                model.money_req_seq = ConvertNullInt(dr["money_req_seq"]);
                model.emp_seq = ConvertNullInt(dr["emp_seq"]);
                model.contact_seq = ConvertNullInt(dr["contact_seq"]);
                model.job_site_seq = ConvertNullInt(dr["job_site_seq"]);
                model.pos_seq = ConvertNullInt(dr["pos_seq"]);
                model.class_seq = ConvertNullInt(dr["class_seq"]);
                model.old_class_seq = ConvertNullInt(dr["old_class_seq"]);
                model.emp_name = dr["emp_name"].ToString();
                model.contact_name = dr["contact_name"].ToString();
                model.traveler_name = dr["traveler_name"].ToString();
                model.pos_name = dr["pos_name"].ToString();
                model.job_site_name = dr["job_site_name"].ToString();

                models.Add(model);
            }

            return models;
        }

        [WebMethod]
        public List<M_FIM_MoneyRequestTravelers> GetList(string money_req_seq)
        {
            DataTable dtb = bll.GetList(money_req_seq);
            var models = new List<M_FIM_MoneyRequestTravelers>();

            foreach (DataRow dr in dtb.Rows)
            {
                var model = new M_FIM_MoneyRequestTravelers();
                model.traveler_seq = Convert.ToInt32(dr["traveler_seq"]);
                model.emp_seq = ConvertNullInt(dr["emp_seq"]);
                model.traveler_name = dr["traveler_name"].ToString();

                models.Add(model);
            }

            return models;
        }

        [WebMethod]
        public M_FIM_MoneyRequestTravelers GetInfo(string seq)
        {
            DataRow dr = bll.GetInfo(seq);
            var model = new M_FIM_MoneyRequestTravelers();
            model.traveler_seq = Convert.ToInt32(dr["traveler_seq"]);
            model.money_req_seq = ConvertNullInt(dr["money_req_seq"]);
            model.emp_seq = ConvertNullInt(dr["emp_seq"]);
            model.contact_seq = ConvertNullInt(dr["contact_seq"]);
            model.job_site_seq = ConvertNullInt(dr["job_site_seq"]);
            model.pos_seq = ConvertNullInt(dr["pos_seq"]);
            model.class_seq = ConvertNullInt(dr["class_seq"]);
            model.old_class_seq = ConvertNullInt(dr["old_class_seq"]);
            model.emp_name = dr["emp_name"].ToString();
            model.contact_name = dr["contact_name"].ToString();
            model.traveler_name = dr["traveler_name"].ToString();
            model.pos_name = dr["pos_name"].ToString();
            model.job_site_name = dr["job_site_name"].ToString();
            return model;
        }

        [WebMethod]
        public void Insert(string money_req_seq
            , string emp_seq
            , string contact_seq
            , string contact_person_seq
            , string job_site_seq
            , string pos_seq
            , string class_seq
            , string old_class_seq
            , string record_status
            , string created_by)
        {
            try
            {
                bll.Insert(money_req_seq
                    , emp_seq
                    , contact_seq
                    , contact_person_seq
                    , job_site_seq
                    , pos_seq
                    , class_seq
                    , old_class_seq
                    , record_status
                    , created_by);
            }
            catch
            {
                throw;
            }
        }

        [WebMethod]
        public void Update(string traveler_seq
            , string money_req_seq
            , string emp_seq
            , string contact_seq
            , string contact_person_seq
            , string job_site_seq
            , string pos_seq
            , string class_seq
            , string old_class_seq
            , string updated_by)
        {
            bll.Update(traveler_seq
                , money_req_seq
                , emp_seq
                , contact_seq
                , contact_person_seq
                , job_site_seq
                , pos_seq
                , class_seq
                , old_class_seq
                , updated_by);
        }

        [WebMethod]
        public void Delete(string traveler_seq
            , string updated_by)
        {
            bll.Delete(traveler_seq
                , updated_by);
        }
    }
}
